//
//  LYouBuyInfoView.m
//  LYouSubscribeApp
//
//  Created by grx on 2018/12/19.
//  Copyright © 2018年 grx. All rights reserved.
//

#import "LYouBuyInfoView.h"
#import "NSString+WPAttributedMarkup.h"
#import "WPAttributedStyleAction.h"
#import "WPHotspotLabel.h"
#import "UILabel+lineSpacing.h"

@interface LYouBuyInfoView()

@property(nonatomic,strong) UIImageView *iconImage;

@end

@implementation LYouBuyInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.0f];
        [self creatUI];
    }
    return self;
}

-(void)creatUI{
    UIScrollView *mainScrollView = [UIScrollView new];
    mainScrollView.bounces = YES;
    mainScrollView.showsHorizontalScrollIndicator = NO;//不显示水平拖地的条
    mainScrollView.showsVerticalScrollIndicator=NO;//不显示垂直拖动的条
    mainScrollView.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.0f];
    [self addSubview:mainScrollView];
    mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-60);
    if ([ISCheckIOS isEqualToString:@"yes"]) {
        mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-20);
    }
    [mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self).offset(0);
        make.height.mas_equalTo(SCREEN_HEIGHT-80);
    }];
    if (SCREEN_HEIGHT<=667) {
        mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT+30);
        if ([ISCheckIOS isEqualToString:@"yes"]) {
            mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT+80);
        }
    }
    /** 背景图片 */
    CGFloat safeBottem = MainWindows.safeAreaInsets.bottom;
    CGFloat hight = 50;
    if (safeBottem>0) {
        hight = 70;
    }
    self.iconImage = [UIImageView new];
    self.iconImage.image = [UIImage imageNamed:@"buyXyIcon"];
    [mainScrollView addSubview:self.iconImage];
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(mainScrollView);
        make.top.equalTo(mainScrollView).offset(hight);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(60);
    }];
    /** 下载超清视频 */
    UILabel *chaoQlable = [UILabel new];
    chaoQlable.text = @"下载超清视频";
    chaoQlable.font = LYFont_Medium(15);
    chaoQlable.textColor = [UIColor whiteColor];
    chaoQlable.textAlignment = NSTextAlignmentCenter;
    chaoQlable.alpha = 1;
    [mainScrollView addSubview:chaoQlable];
    [chaoQlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(0);
        make.top.equalTo(self.iconImage).offset(65);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.height.mas_equalTo(40);
    }];
    /** 下载超清视频描述 */
    UILabel *chaoQDiscrilable = [UILabel new];
    chaoQDiscrilable.text = @"每一段视频壁纸都包含普通和超清两种分辨率，只有会员可以下载无损的最高清晰度原片。";
    chaoQDiscrilable.font = LYFont_Regular(12);
    chaoQDiscrilable.numberOfLines = 0;
    chaoQDiscrilable.textColor = [UIColor whiteColor];
    chaoQDiscrilable.textAlignment = NSTextAlignmentCenter;
    chaoQDiscrilable.alpha = 1;
    [mainScrollView addSubview:chaoQDiscrilable];
    [chaoQDiscrilable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(25);
        make.top.equalTo(chaoQlable.mas_bottom).offset(5);
        make.width.mas_equalTo(SCREEN_WIDTH-50);
    }];
    /** 下划线 */
    UIView *line1 = [UIView new];
    line1.backgroundColor = [UIColor whiteColor];
    line1.alpha = 0.3;
    [mainScrollView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(30);
        make.top.equalTo(chaoQDiscrilable.mas_bottom).offset(25);
        make.width.mas_equalTo(SCREEN_WIDTH-60);
        make.height.mas_equalTo(1);
    }];
    /** 导出超清视频 */
    UILabel *importChaoQlable = [UILabel new];
    importChaoQlable.text = @"导出超清视频 Live Photo";
    importChaoQlable.font = LYFont_Medium(15);
    importChaoQlable.textColor = [UIColor whiteColor];
    importChaoQlable.textAlignment = NSTextAlignmentCenter;
    importChaoQlable.alpha = 1;
    [mainScrollView addSubview:importChaoQlable];
    [importChaoQlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(0);
        make.top.equalTo(line1.mas_bottom).offset(20);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.height.mas_equalTo(40);
    }];
    /** 导出超清视频描述 */
    UILabel *importChaoQDiscrilable = [UILabel new];
    importChaoQDiscrilable.text = @"用最高清晰度的 Live Photo 作为锁屏壁纸，每一次点亮iPhone都是美的享受。";
    importChaoQDiscrilable.font = LYFont_Regular(12);
    importChaoQDiscrilable.numberOfLines = 0;
    importChaoQDiscrilable.textColor = [UIColor whiteColor];
    importChaoQDiscrilable.textAlignment = NSTextAlignmentCenter;
    importChaoQDiscrilable.alpha = 1;
    [mainScrollView addSubview:importChaoQDiscrilable];
    [importChaoQDiscrilable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(25);
        make.top.equalTo(importChaoQlable.mas_bottom).offset(5);
        make.width.mas_equalTo(SCREEN_WIDTH-50);
    }];
    /** 下划线 */
    UIView *line2 = [UIView new];
    line2.backgroundColor = [UIColor whiteColor];
    line2.alpha = 0.3;
    [mainScrollView addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(30);
        make.top.equalTo(importChaoQDiscrilable.mas_bottom).offset(25);
        make.width.mas_equalTo(SCREEN_WIDTH-60);
        make.height.mas_equalTo(1);
    }];
    /** 移除广告 */
    UILabel *removeAdBoardlable = [UILabel new];
    removeAdBoardlable.text = @"移除广告";
    removeAdBoardlable.font = LYFont_Medium(15);
    removeAdBoardlable.textColor = [UIColor whiteColor];
    removeAdBoardlable.textAlignment = NSTextAlignmentCenter;
    removeAdBoardlable.alpha = 1;
    [mainScrollView addSubview:removeAdBoardlable];
    [removeAdBoardlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(0);
        make.top.equalTo(line2.mas_bottom).offset(20);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.height.mas_equalTo(40);
    }];
    /** 移除广告描述 */
    UILabel *removeAdBoardDislable = [UILabel new];
    removeAdBoardDislable.text = @"在你欣赏和寻找适合自己的动态壁纸过程中，可以不被广告打扰。";
    removeAdBoardDislable.font = LYFont_Regular(12);
    removeAdBoardDislable.numberOfLines = 0;
    removeAdBoardDislable.textColor = [UIColor whiteColor];
    removeAdBoardDislable.textAlignment = NSTextAlignmentCenter;
    removeAdBoardDislable.alpha = 1;
    [mainScrollView addSubview:removeAdBoardDislable];
    [removeAdBoardDislable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(25);
        make.top.equalTo(removeAdBoardlable.mas_bottom).offset(5);
        make.width.mas_equalTo(SCREEN_WIDTH-50);
    }];
    /** 下划线 */
    UIView *line3 = [UIView new];
    line3.backgroundColor = [UIColor whiteColor];
    line3.alpha = 0.3;
    [mainScrollView addSubview:line3];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(30);
        make.top.equalTo(removeAdBoardDislable.mas_bottom).offset(25);
        make.width.mas_equalTo(SCREEN_WIDTH-60);
        make.height.mas_equalTo(1);
    }];
    /** 购买描述 */
    WPHotspotLabel *buyDislable=[WPHotspotLabel new];
    buyDislable.font = LYFont_Regular(8);
    buyDislable.numberOfLines = 0;
    buyDislable.textColor = [UIColor lightGrayColor];
    buyDislable.textAlignment = NSTextAlignmentLeft;
    buyDislable.alpha = 0.8;
    [mainScrollView addSubview:buyDislable];
    [buyDislable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(25);
        make.top.equalTo(line3.mas_bottom).offset(20);
        make.width.mas_equalTo(SCREEN_WIDTH-40);
    }];
    NSInteger size;
    if ([ISCheckIOS isEqualToString:@"yes"]) {
        size = 14;
    }else{
        size = 12;
    }
    NSDictionary* xieyStyle = @{@"body":[UIFont fontWithName:@"HelveticaNeue" size:size],
                                @"pro1":[WPAttributedStyleAction styledActionWithAction:^{
                                    NSLog(@"push1==================");
                                    if (self.pushXyControllerBlock) {
                                        self.pushXyControllerBlock(0);
                                    }
                                }],@"pro2":[WPAttributedStyleAction styledActionWithAction:^{
                                    NSLog(@"push2==================");
                                    if (self.pushXyControllerBlock) {
                                        self.pushXyControllerBlock(1);
                                    }
                                }],@"pro3":[WPAttributedStyleAction styledActionWithAction:^{
                                    NSLog(@"push3==================");
                                    if (self.pushXyControllerBlock) {
                                        self.pushXyControllerBlock(2);
                                    }
                                }],@"u": @[[UIColor blueColor],
                                           @{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}
                                           ],@"link": [UIColor whiteColor]};
    buyDislable.attributedText = [@"This enadles a 7 day free trial,followed by a subscription to Vpic Premium for £30.99/yearly.By joining you accept our <pro1><u>Terms of use</u></pro1>,<pro2><u>Privacy Policy</u></pro2> and <pro3><u>Subscription Policy</u></pro3>.This subscription auto-renews at the and of each year term at £30.99,unless cancalled 24-hours in advance.The subscription fee is charged to your iTunes account at confirmation of purchase.You may manage your subscription and turn off auto-renewal by going to your Settings.No cancellation of the current subscription is allowed during active period." attributedStringWithStyleBook:xieyStyle];
    /*! 恢复购买 */
    WPHotspotLabel *recoveryBuyLable=[WPHotspotLabel new];
    recoveryBuyLable.font = LYFont_Regular(13);
    recoveryBuyLable.textColor = [UIColor lightGrayColor];
    recoveryBuyLable.textAlignment = NSTextAlignmentCenter;
    recoveryBuyLable.alpha = 0.8;
    [mainScrollView addSubview:recoveryBuyLable];
    [recoveryBuyLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mainScrollView).offset(25);
        make.top.equalTo(buyDislable.mas_bottom).offset(20);
        make.width.mas_equalTo(SCREEN_WIDTH-50);
        make.height.mas_equalTo(40);

    }];
    NSDictionary* recoverStyle = @{@"body":[UIFont fontWithName:@"HelveticaNeue" size:14.0],@"pro4":[WPAttributedStyleAction styledActionWithAction:^{
                                if (self.recoverBuyBlock) {
                                    self.recoverBuyBlock();
                                }
                                }],@"u": @[[UIColor blueColor],
                                           @{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}
                                           ],@"link": [UIColor whiteColor]};
    recoveryBuyLable.attributedText = [@" <pro4> <u> 恢复购买 </u> </pro4> " attributedStringWithStyleBook:recoverStyle];
    
    if ([ISCheckIOS isEqualToString:@"yes"]) {
        chaoQlable.alpha = 1;
        chaoQDiscrilable.alpha = 1;
        importChaoQlable.alpha = 1;
        importChaoQDiscrilable.alpha = 1;
        removeAdBoardlable.alpha = 1;
        removeAdBoardDislable.alpha = 1;
        buyDislable.alpha = 1;
        recoveryBuyLable.alpha = 1;
        buyDislable.alpha = 1;
        buyDislable.textColor = [UIColor whiteColor];
        recoveryBuyLable.textColor = [UIColor whiteColor];
        /** 隐藏广告 */
//        removeAdBoardlable.hidden = YES;
//        removeAdBoardDislable.hidden = YES;
//        line3.hidden = YES;
//        [buyDislable mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(line2.mas_bottom).offset(20);
//        }];
    }
}

@end
